package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.entity.TbTask;
import com.wang.response.ResultResponse;
import com.wang.service.TbTaskService;
import com.wang.mapper.TbTaskMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class TbTaskServiceImpl implements TbTaskService{
    @Resource
    private TbTaskMapper taskMapper;

    /*
    修改 和添加
     */
    @Override
    public ResultResponse insertTbTask(TbTask tbTask) {
        if (tbTask.getTaskId()!=null){
            int i = this.taskMapper.updateById(tbTask);
            if (i>0){
                return ResultResponse.SUCCESS();
            }else{
                return ResultResponse.FAIED(500, "失败");
            }
        }else {
            int insert = taskMapper.insert(tbTask);
            if (insert>0){
                return ResultResponse.SUCCESS();
            }else{
                return ResultResponse.FAIED(500, "失败");
            }
        }

    }

    @Override
    public ResultResponse removetbtask(Integer  taskId) {
        int i = taskMapper.deleteById(taskId);
        if (i>0){
            return ResultResponse.SUCCESS();
        }else{
            return ResultResponse.FAIED(500, "失败");
        }
    }



    @Override
    public ResultResponse findtbtask(Integer pagesize,Integer pagenum) {
        Page<TbTask> tbTaskPage = new Page<>(pagesize, pagenum);
        QueryWrapper<TbTask> tbTaskQueryWrapper = new QueryWrapper<>();
        Page<TbTask> tbTaskPage1 = taskMapper.selectPage(tbTaskPage, tbTaskQueryWrapper);
        long total = tbTaskPage1.getTotal();
        return ResultResponse.SUCCESS(tbTaskPage1.getRecords(),total);
    }
}




